<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>审核列表(平台)</title>
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/icon.css}">
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.easyui.min.js}"></script>
    <script type="text/javascript">

        //查看图书详情
        function showDetails(index) {
            $('#detail').dialog('open');
            let row = $("#booklist").datagrid("getData").rows[index];
            let detail = row.book;
            console.log(row)
            let number = row.number;
            let imgurl = detail.imgurl;
            if (imgurl.indexOf("http") === -1 && imgurl.indexOf("https") === -1) {
                imgurl = '/manager' + imgurl;
            }
            $("#bookname").textbox('setValue', detail.bookname);
            $("#ISBN").textbox('setValue', detail.iSBN);
            $("#price").textbox('setValue', detail.price);
            $("#number").textbox('setValue', number);
            $("#groupprice").textbox('setValue', detail.groupprice);
            $("#author").textbox('setValue', detail.author);
            $("#pagenumber").textbox('setValue', detail.pagenumber);
            $("#publishdate").textbox('setValue', detail.publishdate);
            $("#pressname").textbox('setValue', detail.press.name);
            $("#authorintroduce").textbox('setValue', detail.authorintroduce);
            $("#bookintroduce").textbox('setValue', detail.bookintroduce);
            $("#file").attr('src', imgurl);
        }

        //工具栏
        var toolbar = [{
            id: 'examine_button',
            text: '审核',
            iconCls: 'icon-edit',
            handler: function () {
                $("#examine_detail").val("");
                $("#examine_status").val("1");
                let selected = $('#booklist').datagrid('getSelected');
                if (!selected) {
                    alert("请选择要审核的条目");
                } else {
                    $('#dd').dialog('open');
                }
            }
        }];
        $(function () {
            $("#booknameKey").val("");
            $("#ISBNKey").val("");
            $("#supplier").val("");
            $('#booklist').datagrid({
                title: '审核列表',
                iconCls: 'icon-save',
                url: '/manager/examine/findAll',
                columns: [
                    [
                        {field: 'id', hidden: true},
                        {field: 'title', title: '审核标题', width: 300, align: 'center'},
                        {
                            field: 'info', title: '审核备注', width: 500, align: 'center',
                            formatter: function (value, row, index) {
                                console.log(value)
                                if (value == null) {
                                    return "--";
                                }
                                return value;
                            }
                        },
                        {
                            field: 'flag', title: '审核状态', width: 80, align: 'center',
                            formatter: function (value, row, index) {
                                if (value === 1) {
                                    return "通过";
                                } else if (value === -1) {
                                    return "未通过";
                                }
                                return "审核中";
                            }
                        },
                        {
                            field: '#',
                            title: '书籍详情',
                            width: 200,
                            align: 'center',
                            formatter: function (value, row, index) {
                                return "<a href='#' onclick='showDetails(" + index + ")'>查看</a>";
                            }
                        },

                        {field: 'book', hidden: true},
                        {field: 'number', hidden: true}
                    ]
                ],
                toolbar: toolbar,
                pagination: true,//表示在datagrid设置分页
                pageSize: 5,
                singleSelect: true,
                pageList: [5, 10, 20],
                onSelect: function (rowIndex, rowData) {
                    if (rowData.flag !== 0) {
                        $("#examine_button").linkbutton("disable");
                    } else {
                        $("#examine_button").linkbutton("enable");
                        $("#examineId").val(rowData.id);
                    }
                }
            });

            //初始化查询栏
            $("#submit_search").linkbutton({iconCls: 'icon-search', plain: true})
                .click(function () {
                    $('#booklist').datagrid({
                        queryParams:
                            {
                                "booknameKey": $("#booknameKey").val(),
                                "ISBNKey": $("#ISBNKey").val(),
                                "supplierId":$("#supplier").combobox('getValue')
                            }
                    });   //点击搜索
                });

            //初始化审核窗口
            $('#dd').dialog({
                title: '图书审核',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                href: '',
                modal: true,
                iconCls: 'icon-save',
                buttons: [{
                    text: '提交',
                    iconCls: 'icon-ok',
                    handler: function () {
                        $("#examine").form({
                            url: "examine/examineBook",
                            success: function (data) {
                                $('#dd').dialog('close');
                                let result = JSON.parse(data);
                                if (result.status !== 2001) {
                                    alert(result.msg);
                                }
                                $('#booklist').datagrid('reload');
                            }
                        })
                        $("#examine").submit();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#dd').dialog('close');
                    }
                }]
            });


            //初始化查看书籍详情窗口
            $('#detail').dialog({
                title: '书籍详情',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                href: '',
                modal: true,
                iconCls: 'icon-save',
            });

            //初始化下拉控件
            $("#supplier").combobox({
                url: "/manager/supplier/findAllNoPages",
                prompt:'请选择供应商',
                value:"",
                valueField: "id",
                textField: "name",
            });


        });
    </script>
</head>
<body>
<form name="searchform" method="post" action="" id="searchform">
    <td width="70" height="30"><strong>审核查询：</strong></td>
    <td height="30">
        <input type="text" name="bookname" id="booknameKey" size=20 placeholder="书籍名称"/>
        <input type="text" name="ISBN" size=20 id="ISBNKey" placeholder="ISBN"/>
        <select name="supplier" id="supplier" style="width:200px">
        </select>
    </td>
    <td>
        <a id="submit_search">查询</a>
    </td>
</form>
<table id="booklist"></table>
<div id="dd">
    <div align="center" style="margin-top: 30px">
        <form id="examine" method="post">
            <table>
                <tr>
                    <input type="hidden" name="examineId" id="examineId">
                    <td>
                        审核状态:
                    </td>
                    <td>
                        <select id="examine_status" name="examineStatus" style="width:100px">
                            <option value="1">通过</option>
                            <option value="-1">不通过</option>
                        </select>
                    </td>
                </tr>
                <tr style="vertical-align:top">
                    <td>
                        审核详情:
                    </td>
                    <td>
                        <textarea id="examine_detail" name="examineDetail" rows="10" cols="30"></textarea>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>

<div id="detail">
    <div align="center" style="margin-top: 30px">
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="bookname" style="width:50%"
                   data-options="label:'书籍名称:',required:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="ISBN" style="width:50%"
                   data-options="label:'ISBN:',required:true,validType:'email'" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="price" style="width:50%"
                   data-options="label:'单价:',required:true,validType:'email'" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="number" style="width:50%"
                   data-options="label:'待上架数量:',required:true,validType:'email'" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="groupprice" style="width:50%"
                   data-options="label:'团购价:',required:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="author" style="width:50%"
                   data-options="label:'作者:',required:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="pagenumber" style="width:50%" data-options="label:'页数:',required:true"
                   readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="publishdate" style="width:50%"
                   data-options="label:'出版日期:',required:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="pressname" style="width:50%" data-options="label:'出版社:',required:true"
                   readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="bookintroduce" style="width:50%;height:60px"
                   data-options="label:'书籍简介:',multiline:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="authorintroduce" style="width:50%;height:60px"
                   data-options="label:'作者简介:',multiline:true" readonly>
        </div>
        <div style="margin-bottom:20px">
            封面图片:&nbsp;&nbsp;&nbsp;&nbsp; <img id="file" src="" style="width:250px" alt="封面"/>
        </div>
    </div>
</div>
</body>
</html>